﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using FTchina.Logic;
using FTchina.Library;

public partial class ui_UserGroupAction : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
            string id = RequestHelper.SafeRequest(Request["id"]);
            if (id.Length > 0)
            {
                ShowModData(id);
            }           
        }
    }

    private void LoadData()
    {

        // 关闭按钮的客户端脚本：
        // 1. 首先确认窗体中表单是否被修改（如果已经被修改，则弹出是否关闭的确认对话框）
        // 2. 然后关闭本窗体，回发父窗体
        btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();

     }

    private void ShowModData(string ItemID)
    {
        if (ItemID == "1")
        {
            AlertLogic.ShowError("此项为系统数据，不允许变更！");
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
        }
        FTchina.Models.UserGroup mUsergroup = FTchina.BLL.UserGroupManager.GetUserGroupById(Convert.ToInt32(ItemID));
        if (mUsergroup != null)
        {
            txbid.Text = mUsergroup.Id.ToString();
            txbgroupname.Text = mUsergroup.Groupname.ToString();
        }
        else
        {
            AlertLogic.ShowResultAndRedirect("无数据！", "提示", HttpContext.Current.Request.Path.ToString(), false);
        }
    }
    protected void btnSaveContinue_Click(object sender, EventArgs e)
    {
        // 1. 这里放置保存窗体中数据的逻辑
        FTchina.Models.UserGroup mUsergroup = new FTchina.Models.UserGroup();
        mUsergroup.Id = txbid.Text.Trim() == "" ? 0 : Convert.ToInt32(txbid.Text);
        mUsergroup.Groupname = txbgroupname.Text;
        AlertLogic.ShowResult(FTchina.BLL.UserGroupManager.AddOrUpdateUserGroup(mUsergroup) > 0);

        // 2. 关闭本窗体，然后回发父窗体
        PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
    }

    //protected void btnSaveRefresh_Click(object sender, EventArgs e)
    //{
    //    // 1. 这里放置保存窗体中数据的逻辑

    //    // 2. 关闭本窗体，然后刷新父窗体
    //    PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
    //}

   
}